#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2e5 + 10;
const db alpha = 0.65;

int mn[N][2], mx[N][2], pos[N][2], ch[N][2], ndn, siz[N], val[N], tsiz[N], rt;

#define ls ch[x][0]
#define rs ch[x][1]
void pu(int x) {
	siz[x] = siz[ls] + siz[rs] + val[x]; tsiz[x] = tsiz[ls] + tsiz[rs] + 1; 
	mn[x][0] = min({ pos[x][0], mn[ls][0], mn[rs][0] }); mn[x][1] = min({ pos[x][1], mn[ls][1], mn[rs][1] });
	mx[x][0] = max({ pos[x][0], mx[ls][0], mx[rs][0] }); mx[x][1] = max({ pos[x][1], mx[ls][1], mx[rs][1] });
}
#undef ls
#undef rs

mt19937 rnd(19491001);

int nd(int x, int y, int v) { ++ndn; pos[ndn][0] = x; pos[ndn][1] = y; val[ndn] = v; ch[ndn][0] = ch[ndn][1] = 0; pu(ndn); return ndn; }
int stk[N], top;
void dfs(int x) { if(!x) return; dfs(ch[x][0]); stk[++top] = x; dfs(ch[x][1]); }
void build(int &x, int l, int r, int op) {
	if(l > r) return x = 0, void(); int mid = l + r >> 1;
	nth_element(stk + l, stk + mid, stk + r + 1, [&](auto a, auto b) { return pos[a][op] < pos[b][op]; });
	x = stk[mid]; ch[x][0] = ch[x][1] = 0; build(ch[x][0], l, mid - 1, op ^ 1); build(ch[x][1], mid + 1, r, op ^ 1); pu(x);
}
void ins(int &x, int v, int op = 0) {
	if(rnd() % (tsiz[x] + 1) == 0) { stk[top = 1] = v; dfs(x); build(x, 1, top, op); return; }
	if(pos[v][op] < pos[x][op]) ins(ch[x][0], v, op ^ 1); else ins(ch[x][1], v, op ^ 1); pu(x);
}
int x, y, a, b;
int query(int o) {
	if(mn[o][0] > a || mn[o][1] > b || mx[o][0] < x || mx[o][1] < y) return 0;
	if(mx[o][0] <= a && mx[o][1] <= b && mn[o][0] >= x && mn[o][1] >= y) return siz[o];
	return query(ch[o][0]) + query(ch[o][1]) + (pos[o][0] <= a && pos[o][1] <= b && pos[o][0] >= x && pos[o][1] >= y) * val[o];
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	mn[0][0] = mn[0][1] = 0x7fffffff; mx[0][1] = mx[0][0] = 0;
	int n = in, ans = 0;
	while(true) {
		int op = in;
		if(op != 3) x = in ^ ans, y = in ^ ans, a = in ^ ans;
		if(op == 1) ins(rt, nd(x, y, a));
		else if(op == 2) b = in ^ ans, ans = query(rt), printf("%d\n", ans);
		else break; //cerr << ndn << endl;
	}
	return 0;
}
